package com.web.dao;

import com.web.controller.web.WebMemberController;
import com.web.entity.Member;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class MemberSqlProvider {


    public String insertSelective(Member record) {
        BEGIN();
        INSERT_INTO("t_member");

        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }

        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getPassword() != null) {
            VALUES("password", "#{password,jdbcType=VARCHAR}");
        }

        if (record.getMemberType() != null) {
            VALUES("member_type", "#{memberType,jdbcType=VARCHAR}");
        }

        if (record.getIdentityNo() != null) {
            VALUES("identity_no", "#{identityNo,jdbcType=VARCHAR}");
        }

        if (record.getAuthStatus() != null) {
            VALUES("auth_status", "#{authStatus,jdbcType=INTEGER}");
        }

        if (record.getHeaderImg() != null) {
            VALUES("header_img", "#{headerImg,jdbcType=VARCHAR}");
        }

        if (record.getInviteCode() != null) {
            VALUES("invite_code", "#{inviteCode,jdbcType=VARCHAR}");
        }

        if (record.getInvitedCode() != null) {
            VALUES("invited_code", "#{invitedCode,jdbcType=VARCHAR}");
        }

        if (record.getNickName() != null) {
            VALUES("nick_name", "#{nickName,jdbcType=VARCHAR}");
        }

        if (record.getGender() != null) {
            VALUES("gender", "#{gender,jdbcType=VARCHAR}");
        }

        if (record.getPayPassword() != null) {
            VALUES("pay_password", "#{payPassword,jdbcType=VARCHAR}");
        }
        if (record.getConsumeAmt() != null) {
            VALUES("consume_amt", "#{consumeAmt,jdbcType=DECIMAL}");
        }

        if (record.getBonusAmt() != null) {
            VALUES("bonus_amt", "#{bonusAmt,jdbcType=DECIMAL}");
        }

        if (record.getLevel() != null) {
            VALUES("level", "#{level,jdbcType=INTEGER}");
        }
        if (record.getEnabled() != null) {
            VALUES("enabled", "#{enabled,jdbcType=INTEGER}");
        }
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(Member record) {
        BEGIN();
        UPDATE("t_member");

        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getPassword() != null) {
            SET("password = #{password,jdbcType=VARCHAR}");
        }

        if (record.getMemberType() != null) {
            SET("member_type = #{memberType,jdbcType=VARCHAR}");
        }

        if (record.getIdentityNo() != null) {
            SET("identity_no = #{identityNo,jdbcType=VARCHAR}");
        }

        if (record.getAuthStatus() != null) {
            SET("auth_status = #{authStatus,jdbcType=INTEGER}");
        }

        if (record.getHeaderImg() != null) {
            SET("header_img = #{headerImg,jdbcType=VARCHAR}");
        }

        if (record.getInviteCode() != null) {
            SET("invite_code = #{inviteCode,jdbcType=VARCHAR}");
        }

        if (record.getInvitedCode() != null) {
            SET("invited_code = #{invitedCode,jdbcType=VARCHAR}");
        }

        if (record.getNickName() != null) {
            SET("nick_name = #{nickName,jdbcType=VARCHAR}");
        }

        if (record.getGender() != null) {
            SET("gender = #{gender,jdbcType=VARCHAR}");
        }

        if (record.getPayPassword() != null) {
            SET("pay_password = #{payPassword,jdbcType=VARCHAR}");
        }

        if (record.getConsumeAmt() != null) {
            SET("consume_amt=#{consumeAmt,jdbcType=DECIMAL}");
        }

        if (record.getBonusAmt() != null) {
            SET("bonus_amt=#{bonusAmt,jdbcType=DECIMAL}");
        }

        if (record.getLevel() != null) {
            SET("level=#{level,jdbcType=INTEGER}");
        }

        if (record.getEnabled() != null) {
            SET("enabled=#{enabled,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }

    public String selectByMember(Member record) {
        BEGIN();
        SELECT("id");
        SELECT("phone");
        SELECT("name");
        SELECT("password");
        SELECT("member_type");
        SELECT("identity_no");
        SELECT("auth_status");
        SELECT("header_img");
        SELECT("invite_code");
        SELECT("invited_code");
        SELECT("nick_name");
        SELECT("gender");
        SELECT("pay_password");
        SELECT("consume_amt");
        SELECT("bonus_amt");
        SELECT("level");
        SELECT("enabled");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_member");
        if (record.getPhone() != null) {
            WHERE("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getName() != null) {
            WHERE("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getPassword() != null) {
            WHERE("password = #{password,jdbcType=VARCHAR}");
        }

        if (record.getMemberType() != null) {
            WHERE("member_type = #{memberType,jdbcType=VARCHAR}");
        }

        if (record.getIdentityNo() != null) {
            WHERE("identity_no = #{identityNo,jdbcType=VARCHAR}");
        }

        if (record.getAuthStatus() != null) {
            WHERE("auth_status = #{authStatus,jdbcType=INTEGER}");
        }

        if (record.getHeaderImg() != null) {
            WHERE("header_img = #{headerImg,jdbcType=VARCHAR}");
        }

        if (record.getInviteCode() != null) {
            WHERE("invite_code = #{inviteCode,jdbcType=VARCHAR}");
        }

        if (record.getInvitedCode() != null) {
            WHERE("invited_code = #{invitedCode,jdbcType=VARCHAR}");
        }

        if (record.getNickName() != null) {
            WHERE("nick_name = #{nickName,jdbcType=VARCHAR}");
        }

        if (record.getGender() != null) {
            WHERE("gender = #{gender,jdbcType=VARCHAR}");
        }

        if (record.getPayPassword() != null) {
            WHERE("pay_password = #{payPassword,jdbcType=VARCHAR}");
        }


        if (record.getConsumeAmt() != null) {
            WHERE("consume_amt=#{consumeAmt,jdbcType=DECIMAL}");
        }

        if (record.getBonusAmt() != null) {
            WHERE("bonus_amt=#{bonusAmt,jdbcType=DECIMAL}");
        }

        if (record.getLevel() != null) {
            SET("level=#{level,jdbcType=INTEGER}");
        }

        if (record.getEnabled() != null) {
            SET("enabled=#{enabled,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            WHERE("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            WHERE("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        if (record.getId() != null) {
            WHERE("id = #{id,jdbcType=BIGINT}");
        }
        return SQL();
    }


    public String selectAllMembers(WebMemberController.MemberColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("phone");
        SELECT("name");
        SELECT("password");
        SELECT("member_type");
        SELECT("identity_no");
        SELECT("auth_status");
        SELECT("header_img");
        SELECT("invite_code");
        SELECT("invited_code");
        SELECT("nick_name");
        SELECT("gender");
        SELECT("pay_password");
        SELECT("consume_amt");
        SELECT("bonus_amt");
        SELECT("level");
        SELECT("enabled");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_member");
        if (record.getPhone() != null&&!"".equals(record.getPhone())) {
            WHERE("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getName() != null&&!"".equals(record.getName())) {
            WHERE("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getIdentityNo() != null&&!"".equals(record.getIdentityNo())) {
            WHERE("identity_no = #{identityNo,jdbcType=VARCHAR}");
        }

        if (record.getMemberType() != null&&!"".equals(record.getMemberType())) {
            WHERE("member_type=#{memberType,jdbcType=VARCHAR}");
        }

        if (record.getLevel() != null&&!"".equals(record.getLevel())) {
            WHERE("level=#{level,jdbcType=INTEGER}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }



}